/**
 * https://leetcode-cn.com/problems/search-in-rotated-sorted-array/
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
 var search = function(nums, target) {
  let bias = 0;
  // get bias;
  for (let i = 0; i < nums.length - 1; i++) {
      if (nums[i + 1] < nums[i]) {
          bias = i+1;
          break;
      }
  }
  let l = 0, r = nums.length - 1;
  while(l <= r) {
      let mid = (l + r) >> 1;
      let midOffset = (mid + bias) % nums.length;
      if (nums[midOffset] === target) {
          return midOffset;
      } else if (nums[midOffset] > target) {
          r = mid - 1;
      } else {
          l = mid + 1;
      }
  }
  return -1;
};